{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1.0\n",
       "1    3.0\n",
       "2    5.0\n",
       "3    NaN\n",
       "dtype: float64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Series([1, 3, 5, np.nan])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    0\n",
       "1    1\n",
       "2    2\n",
       "3    3\n",
       "4    4\n",
       "dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Series(range(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    0\n",
       "b    1\n",
       "c    2\n",
       "d    3\n",
       "e    4\n",
       "dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Series(range(5), index = list('abcde')) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "dates = pd.date_range(start='20180101', end='20181231', freq='M')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-01-31</th>\n",
       "      <td>-0.786583</td>\n",
       "      <td>0.983111</td>\n",
       "      <td>-0.096125</td>\n",
       "      <td>-0.890824</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-28</th>\n",
       "      <td>-0.385960</td>\n",
       "      <td>0.003621</td>\n",
       "      <td>-1.769511</td>\n",
       "      <td>-0.258433</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-31</th>\n",
       "      <td>0.045560</td>\n",
       "      <td>-1.344490</td>\n",
       "      <td>1.150420</td>\n",
       "      <td>-0.035526</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-04-30</th>\n",
       "      <td>-2.167921</td>\n",
       "      <td>-0.970068</td>\n",
       "      <td>0.630374</td>\n",
       "      <td>0.942068</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-05-31</th>\n",
       "      <td>0.349988</td>\n",
       "      <td>-0.222268</td>\n",
       "      <td>-1.376965</td>\n",
       "      <td>0.451286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-30</th>\n",
       "      <td>1.226831</td>\n",
       "      <td>-0.516007</td>\n",
       "      <td>0.534590</td>\n",
       "      <td>2.004487</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-07-31</th>\n",
       "      <td>1.156537</td>\n",
       "      <td>1.046224</td>\n",
       "      <td>-1.090686</td>\n",
       "      <td>-2.302874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31</th>\n",
       "      <td>-0.435869</td>\n",
       "      <td>0.966160</td>\n",
       "      <td>0.763770</td>\n",
       "      <td>0.165130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-09-30</th>\n",
       "      <td>0.310549</td>\n",
       "      <td>0.848405</td>\n",
       "      <td>0.549327</td>\n",
       "      <td>0.877564</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-10-31</th>\n",
       "      <td>-1.375621</td>\n",
       "      <td>-0.327555</td>\n",
       "      <td>0.631499</td>\n",
       "      <td>1.882921</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-11-30</th>\n",
       "      <td>-1.056021</td>\n",
       "      <td>0.761832</td>\n",
       "      <td>1.055232</td>\n",
       "      <td>1.779039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-12-31</th>\n",
       "      <td>-0.663059</td>\n",
       "      <td>0.035842</td>\n",
       "      <td>-2.456848</td>\n",
       "      <td>-0.236888</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2018-01-31 -0.786583  0.983111 -0.096125 -0.890824\n",
       "2018-02-28 -0.385960  0.003621 -1.769511 -0.258433\n",
       "2018-03-31  0.045560 -1.344490  1.150420 -0.035526\n",
       "2018-04-30 -2.167921 -0.970068  0.630374  0.942068\n",
       "2018-05-31  0.349988 -0.222268 -1.376965  0.451286\n",
       "2018-06-30  1.226831 -0.516007  0.534590  2.004487\n",
       "2018-07-31  1.156537  1.046224 -1.090686 -2.302874\n",
       "2018-08-31 -0.435869  0.966160  0.763770  0.165130\n",
       "2018-09-30  0.310549  0.848405  0.549327  0.877564\n",
       "2018-10-31 -1.375621 -0.327555  0.631499  1.882921\n",
       "2018-11-30 -1.056021  0.761832  1.055232  1.779039\n",
       "2018-12-31 -0.663059  0.035842 -2.456848 -0.236888"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(np.random.randn(12,4),\n",
    "                 index = dates,\n",
    "                 columns = list('ABCD'))\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame({'A': np.random.randint(1, 100, 4),\n",
    "                   'B': pd.date_range(start='20180301', periods=4, freq='D'),\n",
    "                   'C': pd.Series([1, 2, 3, 4],\n",
    "                                  index=['zhang', 'li', 'zhou', 'wang'],\n",
    "                                  dtype='float32'),\n",
    "                   'D': np.array([3] * 4, dtype='int32'),\n",
    "                   'E': pd.Categorical([\"test\", \"train\", \"test\", \"train\"]),\n",
    "                   'F': 'foo'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "        A          B    C  D      E    F\n",
      "zhang  97 2018-03-01  1.0  3   test  foo\n",
      "li     76 2018-03-02  2.0  3  train  foo\n",
      "zhou   36 2018-03-03  3.0  3   test  foo\n",
      "wang    1 2018-03-04  4.0  3  train  foo\n"
     ]
    }
   ],
   "source": [
    "df.sort_index(axis=0, ascending=False) #对行进行降序排序\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
